package com.wzt.lianfirecontrol.adapter.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.adapter.BaseRecyclerAdapter;
import com.wzt.lianfirecontrol.bean.recode.home.HomeJianCeModel;
import com.wzt.lianfirecontrol.utils.GildeUtils;
import com.wzt.lianfirecontrol.utils.StringUtils;

public class HomeVideoListAdapter extends BaseRecyclerAdapter<HomeJianCeModel> {


    private Context context;

    public HomeVideoListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_home_video_list, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, HomeJianCeModel data) {
        if (viewHolder instanceof MyViewHolder){
            setData((MyViewHolder)viewHolder, data, RealPosition);
        }

    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private RelativeLayout rl_home_list_item;
        private ImageView iv_item_img;
        private TextView tv_item_name;

        public MyViewHolder(View itemView) {
            super(itemView);
            initDataView(this, itemView);
        }
    }

    private void initDataView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.rl_home_list_item = itemView.findViewById(R.id.rl_home_list_item);
        myViewHolder.iv_item_img = itemView.findViewById(R.id.iv_item_img);
        myViewHolder.tv_item_name = itemView.findViewById(R.id.tv_item_name);
    }

    private void setData(MyViewHolder viewHolder, final HomeJianCeModel data, int position) {
        viewHolder.iv_item_img.setVisibility(View.VISIBLE);
        if (!StringUtils.isEmpty(data.getLogoUri()) && data.getLogoUri().startsWith("http")){
            GildeUtils.loadImage(context, viewHolder.iv_item_img, data.getLogoUri());
            viewHolder.iv_item_img.setVisibility(View.VISIBLE);
        }else {
            if (0 != data.getLogoImgRes()){
                GildeUtils.loadImage(context, viewHolder.iv_item_img, data.getLogoImgRes());
                viewHolder.iv_item_img.setVisibility(View.VISIBLE);
            }else {
                viewHolder.iv_item_img.setVisibility(View.GONE);
            }
        }
        if (StringUtils.isEmpty(data.getSysName())){
            viewHolder.tv_item_name.setVisibility(View.GONE);
        }else{
            viewHolder.tv_item_name.setVisibility(View.VISIBLE);
            viewHolder.tv_item_name.setText(data.getSysName());
        }

    }

    
    
}
